<?php if ($this->id) : ?>
<h2><?php echo $this->translate('Edit page'); ?></h2>
<?php else : ?>
<h2><?php echo $this->translate('Create new page'); ?></h2>
<?php endif; ?>
<form id="edit_page" method="post" action="<?php echo $this->url(); ?>">
    <table style="width:100%">
        <!-- Page enabled checkbox -->
        <tr>
            <td style="width:170px;">
                <?php echo $this->translate('Page enabled'); ?>:
            </td>
            <td>
                <?php
                    echo $this->formCheckbox('enabled', 1, array('checked' => $this->form->getValue('enabled')));
                ?>
            </td>
        </tr>
        <?php echo $this->partial('page/_errors.phtml', array('form' => $this->form, 'field_name' => 'enabled')); ?>

        <!-- Page key text input -->
        <tr>
            <td style="width:170px;">
                <?php echo $this->translate('Page key'); ?>:
                <span style="color:red">*</span>
            </td>
            <td>
                <?php
                    echo $this->formText('key', $this->form->getValue('key'));
                ?>
            </td>
        </tr>
        <?php echo $this->partial('page/_errors.phtml', array('form' => $this->form, 'field_name' => 'key')); ?>

        <!-- Page multilanguage fields -->
        <tr>
            <td colspan="2">
            <?php foreach ($this->languages as $language) : ?>
            <?php
                $this->tabPane("langtabs", $this->partial('page/_tab.phtml', array('language' => $language, 'form' => $this->form)), array('title' => $language->getName()));
            ?>
            <?php endforeach; ?>
            <?php echo $this->tabContainer("langtabs", array(), array('class' => 'flora')); ?>
            </td>
        </tr>

        <!-- Submit button -->
        <tr>
            <td colspan="2">
                <center>
                    <small>
                        <span style="color:red">*</span>
                        <?php echo $this->translate('Required fields.'); ?>
                    </small>
                    <br />
                    <br />
                    <input type="button" value="<?php echo $this->translate('Back'); ?>" onclick="window.location='<?php echo $this->url(array('controller' => 'page', 'action' => 'index')); ?>'" />
                    <?php
                        echo $this->formSubmit('sb', $this->translate('Save'), array('onclick' => 'submitForm();'));
                    ?>
                </center>
            </td>
        </tr>
    </table>
</form>

<script>
submitForm = function() {

    <?php foreach ($this->languages as $language) : ?>
    var ctnt = tinyMCE.get('content_<?php echo $language->getId(); ?>').getContent();
    if (!ctnt) {
        MessageBox.clearMessages();
        MessageBox.displayMessage(MessageBox.TYPE_ERROR, '<?php echo addslashes($this->translate('Required fields.')); ?>');
    }
    <?php endforeach; ?>

    <?php foreach ($this->languages as $language) : ?>
    tinyMCE.get('content_<?php echo $language->getId(); ?>').save();
    <?php endforeach; ?>
}

$(document).ready(function(){
    setTimeout('initMCE()', 300);
});
initMCE = function() {
    <?php foreach ($this->languages as $language) : ?>
    tinyMCE.get('content_<?php echo $language->getId(); ?>').setContent($('textarea[name=content_<?php echo $language->getId(); ?>]').text());
    <?php endforeach; ?>
}
</script>
